<?php

namespace Admin\Models\overt;

use Admin\Models\BaseModel;
class XhovertMsgtemplate extends BaseModel
{

    /**
     *
     * @var integer
     */
    public $iMTId;

    /**
     *
     * @var string
     */
    public $iAppCode;

    /**
     *
     * @var string
     */
    public $sContent;

    /**
     *
     * @var integer
     */
    public $bDelete;

    /**
     *
     * @var string
     */
    public $tCreateDate;

    /**
     *
     * @var string
     */
    public $iCreateUserId;

    /**
     *
     * @var string
     */
    public $tLastModifyDate;

    /**
     *
     * @var string
     */
    public $iLastModifyUserId;

    /**
     * Initialize method for model.
     */
    public function initialize()
    {
        parent::initialize();
        $this->setSource("XHOvert_MsgTemplate");
    }

    /**
     * Returns table name mapped in the model.
     *
     * @return string
     */
    public function getSource()
    {
        return 'XHOvert_MsgTemplate';
    }

    /**
     * Allows to query a set of records that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhovertMsgtemplate[]
     */
    public static function find($parameters = null)
    {
        return parent::find($parameters);
    }

    /**
     * Allows to query the first record that match the specified conditions
     *
     * @param mixed $parameters
     * @return XhovertMsgtemplate
     */
    public static function findFirst($parameters = null)
    {
        return parent::findFirst($parameters);
    }

    /**
     * 新建或更改记录
     *
     * @param $data
     * @return XhovertMsgtemplate
     *
     * create by ck 20161025
     */
    public static function createRecord($data)
    {
        $obj = isset($data['iMTId']) ? self::findFirst($data['iMTId']) : new self;
        $obj or $obj = new self;
        $obj->assign($data);
        return $obj;
    }

    /**
     * 批量删除并返回结果
     *
     * @param $idArr
     * @return mixed
     *
     * create by ck 20161025
     */
    public static function deleteRecordById($idArr)
    {
        return self::find([
            'conditions' => 'bDelete = 0 AND iMTId IN ({idArr:array})',
            'bind'       => ['idArr' => $idArr]
        ])->delete();
    }

}
